import pandas as pd

from Model import RandomForestRegressorModel
from dataManagement.MetaDataInterface import MetaDataInterface
import os

class modelInterface:
    def __init__(self, dbName='MetaDataBased'):
        self.dbname  = dbName
    def trainRFRbyCV(self,excel_name,features_name,target_name):
        abPath = os.path.dirname(os.path.abspath(__file__))
        pathName = []
        for n in abPath.split('\\'):
            pathName.append(n)
            if n == 'flask_backend':
                break
        filePath = os.path.join('\\'.join(pathName), 'dataManagement',self.dbname, excel_name + '.xlsx')
        df_all = pd.read_excel(filePath)
        features = df_all.loc[:,features_name]
        target = df_all.loc[:,target_name]
        rfrCV = RandomForestRegressorModel()
        rfrCV.trainByKfold(features,target) #训练模型
        resCV_dic = rfrCV.modelEvaluate() #评估训练结果

